<%@ page import="edu.chinasoft.domain.Application" %>
<%@ page import="java.util.Date,edu.chinasoft.domain.Application" %>
<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改请假申请单</title>
<script type="text/javascript">
    function getDays() {
        var beginElement = document.getElementsByName("applicationBegin");
        var begintime = beginElement[0].value;
        var beginDate = new Date(begintime);
        console.log("开始时间time："+begintime);
        console.log("开始时间date："+beginDate);
        var endElement = document.getElementsByName("applicationEnd");
        var endtime = endElement[0].value;
        var endDate = new Date(endtime);
        console.log("结束时间time："+endtime);
        console.log("结束时间date："+endDate);
        var days = parseInt(endDate-beginDate)/(1000*60*60*24);
        console.log("相差时间："+days+"天");
        var datenumberElement = document.getElementById("datenumber");
        datenumberElement.value = days;

    }
</script>
</head>
<body>
<h3>修改请假单基本信息</h3>
<form action="${pageContext.request.contextPath }/applicationHandler/updateApplication.do" method="post">
	<fieldset>     <!--分组标签-->
		<legend>请假单基本信息</legend>  <!--设置标题-->
		请假单id：<input type="text" name='applicationId' readonly="readonly" value="${updateapplication.applicationId }"/><br/>
		请假者：<input type="text" name='applicationusername' readonly="readonly" value="${userLogin.userName }"/><br/>
		请假事项：<input type="text" name='applicationContent' value="${updateapplication.applicationContent }"><br/>

		<%
			Application applicationById = (Application)session.getAttribute("updateapplication");
			Date beginDate = applicationById.getApplicationBegin();
			String begintime = "";
			int beginyear = beginDate.getYear()+1900;
			int beginmonth = beginDate.getMonth()+1;
			int beginday = beginDate.getDate();
			begintime += beginyear;
			if(beginmonth <= 9){
				begintime = begintime + "-"+"0"+beginmonth;
			}else{
				begintime = begintime + "-"+beginmonth;
			}
			if(beginday <= 9){
				begintime = begintime + "-"+"0"+beginday;
			}else{
				begintime = begintime + "-"+beginday;
			}
		%>
		开始时间：<input type="date" name="applicationBegin" value="<%= begintime %>" onblur="getDays()"/><br/>

		<%
			Date endDate = applicationById.getApplicationEnd();
			String endtime = "";
			int year = endDate.getYear()+1900;
			int month = endDate.getMonth()+1;
			int day = endDate.getDate();
			endtime += year;
			if(month <= 9){
				endtime = endtime + "-"+"0"+month;
			}else{
				endtime = endtime + "-"+month;
			}
			if(day <= 9){
				endtime = endtime + "-"+"0"+day;
			}else{
				endtime = endtime + "-"+day;
			}
		%>
		结束时间：<input type="date" name="applicationEnd" value="<%= endtime %>" onblur="getDays()"/><br/>
		请假天数：<input type="text" id='datenumber' readonly="readonly" onclick="getDays()"> <br/>
		审批者：
		<select name='selectapprovaluser'>
			<option value=${updateapplication.approvalUser.userId }>${updateapplication.approvalUser.userName }</option>
			<c:forEach var="user" items="${approvalUserInfo}">
				<option value=${user.userName}>${user.userName}</option>
			</c:forEach>

		</select>
		<br/>
		<input type="submit" value='更新请假单'>
		<input type="reset" value='清空'>
	</fieldset>
</form>

</body>
</html>